package argirithm;

import java.util.Collections;
import java.util.Map;

//7进制转换成10进制
public class Demo {
    public static void main(String[] args) {
        int c = parseInt("123",7);
        System.out.println(c);

        System.out.println(('a'));
    }
    public static int parseInt(String num , Integer radix){
        int s =1;
        int end = 0;
        if (num.startsWith("-")){
            s = -1;
            end = 1;
        }
        int weight=1;
        int sum=0;
        for (int i = num.length()-1;i>=end;i--){
            char c = num.charAt(i);
              int n = c - '0';
              if (n>=radix || n<0 ){
                  throw new NumberFormatException("数字异常"+n);
              }
              sum += n*weight;
              weight *= radix;
        }
        return s==-1?-sum:sum;
    }
}
